package net.tksl.crm.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import net.tksl.crm.dao.DetalleCompendioDao;
import net.tksl.crm.dao.bd.DetalleCompendioBD;

@Repository("detalleCompendioDaoImpl")
public class DetalleCompendioDaoImpl implements DetalleCompendioDao {

	@Autowired
	@Qualifier("sessionFactory")
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<DetalleCompendioBD> listarDetallesPorCodigoTabla(String codigoTabla) {
		String hql = "from DetalleCompendioBD d where d.codTabla = ? order by d.descripcionElemento asc";
		Session sesion = sessionFactory.getCurrentSession();
		Query query = sesion.createQuery(hql);
		
		int i = 0;
		query.setParameter(i,codigoTabla);i++;
		
		List<DetalleCompendioBD> lista = (List<DetalleCompendioBD>)query.list();
		
		return lista;
	}

}
